package com.zj.leetcode.easy.hash;

import java.util.HashMap;
import java.util.Map;

/**
 * @program: algorithm
 * @description: 存在重复元素
 * 217 contains-duplicate
 * @author: Zhang Bo
 * @create: 2022-01-14 17:05
 **/
public class ContainsDuplicate {
    public static void main(String[] args) {
        int[] nums = {1, 2, 3, 1};
        Solution solution = new ContainsDuplicate().new Solution();
        System.out.println(solution.containsDuplicate(nums));
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public boolean containsDuplicate(int[] nums) {


            if (nums.length <= 1) {
                return false;
            }
            Map<Integer, Integer> map = new HashMap<>();
            for (int i = 0; i < nums.length; i++) {
                if (map.containsKey(nums[i])) {
                    return true;
                }

                map.put(nums[i], i);

            }

            return false;

        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}
